<template>>
  <el-table :data="filterTableData" style="width: 100%">
    
    <el-table-column label="ID" prop="id" />
    <el-table-column label="Name" prop="name" />
    <el-table-column align="right">
      <template #header>
        <el-input v-model="search" size="small" placeholder="请输入标签查找"></el-input>
      </template>
      <template #default="scope">
        <el-button size="small" @click="handleReset(scope.$index, scope.row)">
          重置密码
        </el-button>
        <el-button
          size="small"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)"
        >
          删除
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script lang="ts" setup>
import { computed, ref } from 'vue'
import {useAccountStore} from '@/stores/account.ts'
import { ta } from 'element-plus/es/locales.mjs';
import {useEntryStore} from '@/stores/entry'
const accountStore=useAccountStore();
const entryStore=useEntryStore()
interface User {
  id:number,
  name: string
}
let search = ref('')
const tableData = ref<User[]>([
  {
    id:1,
    name:'sdffd'
  }
])
async function getTag(){
  const response= await accountStore.getAccount(entryStore.token);
  tableData.value=response.data.data;
}
getTag();

const filterTableData = computed(() =>
  tableData.value.filter(
    (data) =>
      !search.value ||
      data.name.toLowerCase().includes(search.value.toLowerCase())
  )
)

async function handleReset  (index: number, row: User) {
  const accountId = row.id;
  await accountStore.resetAccount(entryStore.token ,accountId)
}

async function handleDelete (index: number, row: User) {
  tableData.value.splice(index, 1)
  const accountId = row.id;
  await accountStore.deleteAccount(entryStore.token ,accountId);
}

</script>
